package com.firesrc.web;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.firesrc.bean.MailDayAmount;
import com.firesrc.service.MailDayAmountService;
import com.firesrc.service.impl.MailDayAmountServiceImpl;
import com.firesrc.util.SystemUtil;

/**
 * Servlet implementation class MailDayAmountServlet
 */
public class MailDayAmountServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public MailDayAmountServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
			IOException {
		MailDayAmountService service = new MailDayAmountServiceImpl();
		List<MailDayAmount> list = new ArrayList<MailDayAmount>();
		String type = request.getParameter("type");
		String name = "";
		if ("all".equals(type)) {
			list = service.getAllList();
			name = "全部";
		} else if ("today".equals(type)) {
			name = "今天 " + SystemUtil.getCurrentDateStringYYYYMMDD();
			list = service.getTodayList();
		}
		request.setAttribute("list", list);
		request.setAttribute("name", name);
		request.getRequestDispatcher("mailDayAmountList.jsp").forward(request, response);
	}
}
